#!/bin/bash - 
#===============================================================================
#
#          FILE: common.sh
# 
#         USAGE: ./common.sh 
# 
#   DESCRIPTION: Common Library
# 
#       OPTIONS: ---
#  REQUIREMENTS: vlc, crontab
#          BUGS: ---
#         NOTES: ---
#        AUTHOR: YOUR NAME (), 
#  ORGANIZATION: 
#       CREATED: 01/29/2021 16:40
#      REVISION:  ---
#===============================================================================

set -o nounset                              # Treat unset variables as an error

checkDependency()
{
    software=''

    which crontab > /dev/null
    [ ! $? -eq 0 ] && software=$software' crontab '

    which curl > /dev/null
    [ ! $? -eq 0 ] && software=$software' curl '

    if [ -n "$software" ] ; then
        echo -e "\e[1;31mPlease execute `sudo apt install $software`\e[0m" && exit 1;
    fi
}

addSchedule()
{
    scriptFile="$WORKDIR/notify.sh"
    chmod +x "$scriptFile"
    crontab -l|grep -q $scriptFile

    if [ ! $? -eq 0 ] ; then
        crontab -l | { cat; echo "* 6 * * * $scriptFile 2&>1 >> $WORKDIR/notify.log"; } | crontab -
    fi
}


CONFIG_FILE="$WORKDIR/config.conf"
STORE_FILE="$WORKDIR/tasks.txt"
LOG_FILE="$WORKDIR/reviewlog.txt" 

checkDependency
addSchedule
